package com.zfl.thread.day03;


import lombok.Synchronized;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class DeadLockDemo01 {
    public static Object lockA = new Object();
    public static Object lockB = new Object();


    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lockA) {
                System.out.println(Thread.currentThread().getName() + "获得一把筷子，想要获取B的筷子");
                synchronized (lockB) {
                    System.out.println(Thread.currentThread().getName() + "获取到两根筷子");
                }
            }
        }, "A").start();
        ;
        new Thread(() -> {
            synchronized (lockB) {
                System.out.println(Thread.currentThread().getName() + "获得一把筷子，想要获取A的筷子");
                synchronized (lockA) {
                    System.out.println(Thread.currentThread().getName() + "获取到两根筷子");
                }
            }
        }, "B").start();

    }
}
